package com.im.partchat.topic;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;

import com.im.partchat.topic.widget.MProgressDialog;

/**
 * 除了每次打开的欢迎页面之外 的所有activity都需要继承本类。
 * 功能：
 * 1、强行在onCreate里先验证是否初始化成功：调用checkInit()。若没有，先在本类里初始化，才能往下走子类的onCreate
 * 2、强行在onResume 和 onPause里插入友盟的统计API
 * 3、提供公共方法checkLogin，检查用户是否登录
 * 4、提供公共方法initProgressDialog，需要弹出加载中弹框的activity子类，需要先在oncreate里调用initProgressDialog
 * 5、提供获取当前登录用户的id方法getUserID，若没登录，返回""
 * 6、提供其他方法，比如跳转都聊天界面，跳转到个人主页，隐藏弹出键盘
 */
public  class BaseActivity extends AppCompatActivity {
	private static final int notifiId = 11;

	public MProgressDialog progress;
	public final static int NETWORK_SUCCESS_DATA_RIGHT = 0x01;
	public final static int NETWORK_SUCCESS_PAGER_RIGHT = 0x02;
	public final static int NETWORK_OTHER = 0x19;
	public final static int NETWORK_SUCCESS_DATA_ERROR = 0x06;
	public final static int NETWORK_FAIL = 0x05;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	
	public void initProgressDialog() {
		initProgressDialog(true, null);
	}

	public void initProgressDialog(boolean cancel, String message) {
		initProgressDialog(this, cancel, message);
	}

	public void initProgressDialog(Context mContext, boolean cancel,
			String message) {
		progress = new MProgressDialog(mContext, cancel);
	}

	public void showErrorToast() {
		showErrorToast("无法连接到网络\n请稍后再试");
	}

	
	public void showErrorToast(String err) {
		Toast.makeText(getApplicationContext(), err, Toast.LENGTH_SHORT).show();
	}

	public void hideKeyboard(View v) {
		((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
				.hideSoftInputFromWindow(v.getWindowToken(),
						InputMethodManager.HIDE_NOT_ALWAYS);
	}

	public void hideKeyboard() {
		hideKeyboard(getWindow().getDecorView());
	}
	
	public void showKeyboard(EditText et) {
		((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
				.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
	}
	
}
